local f = CreateFrame("Statusbar", nil, UIParent)
f:Hide()

f:SetScript("OnUpdate", function (self, elapsed)
	local timeleft = self.timeleft - elapsed
	if timeleft < 0 then
		self:Hide()
	else
		self:SetValue(timeleft)
		self.timeleft = timeleft
	end
end)

f.missing = UnitManaMax"player" - UnitMana"player"
f:SetMinMaxValues(0, 5)
f:SetOrientation"HORIZONTAL"
f:RegisterEvent"PLAYER_LOGIN"
local t = f:CreateFontString(nil, "OVERLAY")
t:SetAllPoints()
t:SetFontObject(GameFontHighlightSmall)
t:SetText("Mana regen")

f:SetScript("OnEvent", function (self, ...)
	local anchor = Grid2LayoutFrame or GridLayoutFrame
	local lsm = LibStub("LibSharedMedia-3.0")
	self:SetStatusBarTexture(lsm:Fetch("statusbar", "Otravi"))
	self:SetStatusBarColor(0.1, 0.3, 1.0, 1.0)
	self:SetHeight(12)
	self:SetPoint("TOP", anchor, "BOTTOM", 0, -2)
	self:SetPoint("LEFT", anchor)	
	self:SetPoint("RIGHT", anchor)
	self:UnregisterEvent"PLAYER_LOGIN"
	self:RegisterEvent"UNIT_MANA"
	self:SetScript("OnEvent", function (self, event, unit)
		if unit ~= "player" or UnitPowerType"player" ~= 0 then return end
		local missing = UnitManaMax"player" - UnitMana"player"
		if self.missing < missing then
			self.timeleft = 5
			self:SetValue(5)
			self:Show()
		end
		self.missing = missing
	end)
end)
